package demo.ybt;

import java.util.Scanner;
import java.util.Stack;

public class P1321 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int s=sc.nextInt();

        Stack<Integer> stack = new Stack<>();
        char[] chars = String.valueOf(n).toCharArray();
        int j = 0;
        for (int i = 0; i < s; ) {
            if (j < chars.length) {
                int cur = chars[j] - '0';
                if (!stack.empty() && cur < stack.peek()) {
                    //前面这个数比现在这个数要大，要移除前面这个数
                    stack.pop();
                    i++;
                } else {
                    //加入到栈里面
                    stack.add(cur);
                    j++;
                }
            } else if (!stack.empty()) {
                stack.pop();
                i++;
            } else {
                System.out.print(-1);;
            }
        }
        int res = 0;
        int ts = 1;
        for (Integer i : stack) {
            res = res * ts + i;
            ts = ts * 10;
        }
        System.out.print(res);
    }
}
